<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>css选择器</title>
    <style>

        #d2{
            background-color: red;
        }
        .error{
            background-color: red;
        }
        .success{
            background-color: green;
        }
        .msg{
            color:white;
        }
        *{
            font-style: italic;
        }
        /*伪类选择器*/
        #d2:hover{
            background-color: yellow;
        }
        #d2,h4,.error{
            text-decoration: underline;
        }
        a:link{
            color: gray;
        }
        a:visited{
            color:green;
        }
        a:hover{
            color: pink;
        }
        a:active{
            color: hotpink;
        }
        [type="text"]{
            background-color: yellow;
        }
        /*后代选择器*/
        div span{
            color:palegreen;
        }
        #d1>div>span{
            color: blue;
        }
    </style>
</head>
<body>
<h4>我是标题</h4>
<h4>我是标题</h4>
<p>我是段落</p>

<h4>我是标题</h4>
<div>我是div1</div>
<div id="d2">我是div2</div>
<div>我是div3</div>
<span class="error msg">用户名被占用</span>
<span class="error msg">两次密码不一致</span>
<span class="success msg">格式正确</span>
<span class="success msg">邮箱格式正确</span>
<hr>
<a href="https://baidu.com">超链接1</a>
<a href="sdhas">超链接2</a>
<input type="text">
<input type="password">
<hr>
<div id="d1">
    <span>文字1</span>
    <div>
        <span>2</span>
        <b>测试文字</b>
    </div>
    <span>文字3</span>
</div>
</body>
</html>